# —*— coding: utf-8 -*-

import os

# pip install python-docx
from docx.document import Document

from py_word import Word, py_dir_path, picture_path

if __name__ == '__main__':
    word_path = os.path.join(py_dir_path, 'document.docx')
    # 只能读取docx格式word文档，而且要求绝对路径
    document: Document = Word(word_path)

    # 段落
    for paragraph in document.paragraphs:
        print(type(paragraph))
        pass

    # 表格
    for table in document.tables:
        print(type(table))
        pass

    # 添加分页符
    document.add_page_break()
    # 添加图片
    document.add_picture(picture_path)

    # 文档结尾追加段落
    document.add_paragraph(text='document.add_paragraph')

    # 另存为
    document.save(os.path.join(py_dir_path, 'word.docx'))

    pass
